import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
 class Main {
    public static void main(String[] args) {
        int n,q;
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        q=sc.nextInt();
        long[] arr=new long[n+1];

        for(int i=1;i<n+1;i++)
            arr[i]=arr[i-1]+sc.nextInt();

        while(q!=0){
            int l,r;
            l=sc.nextInt();
            r=sc.nextInt();
            System.out.println(arr[r]-arr[l-1]);
            q--;

        }

    }
}

// 注意类名必须为 Main, 不要有任何 package xxx 信息
 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        // 注意 hasNext 和 hasNextLine 的区别

        int n = in.nextInt();
        int m = in.nextInt();
        int q = in.nextInt();


        long[][] arr = new long[n + 1][m + 1];

        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++) {
                arr[i][j] = arr[i - 1][j] + arr[i][j - 1] + in.nextInt() - arr[i - 1][j - 1];


            }

        while (q != 0) {
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int x2 = in.nextInt();
            int y2 = in.nextInt();

            long num = arr[x2][y2] + arr[x1 - 1][y1 - 1] - arr[x2][y1 - 1] - arr[x1 -
                    1][y2];
            System.out.println(num);
            q--;


        }








    }
}